package com.ht.shop.service.impl;

import com.ht.shop.dao.CartDao;
import com.ht.shop.dao.impl.CartDaoImpl;
import com.ht.shop.pojo.CartItem;
import com.ht.shop.service.CartService;
import com.ht.shop.utils.DBUtils;
import com.ht.shop.utils.SqlUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.util.List;

public class CartServiceImpl implements CartService {
    private CartDao cartDao = new CartDaoImpl();

    @Override
    public void addCart(String goodId, long uid, int num) throws Exception {
        Long count = cartDao.findCountByUidAndPid(goodId, uid);
        if (count >0) {
            cartDao.updateNum(goodId,uid,num);
        }else {
            cartDao.addCart(goodId,uid,num);
        }
    }

    @Override
    public List<CartItem> findCartByUid(long uid) {

        return cartDao.findCartByUid(uid);
    }

    @Override
    public void deleteByUid(long uid) {

        cartDao.deleteByUid(uid);
    }
}
